package com.ruoyi.common.rabbitmq.consumer;

import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper;
import com.baomidou.mybatisplus.core.conditions.update.UpdateWrapper;
import com.ruoyi.common.business.entity.YytMember;
import com.ruoyi.common.business.service.YytMemberService;
import lombok.extern.slf4j.Slf4j;
import org.springframework.amqp.rabbit.annotation.RabbitListener;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Component;

import javax.xml.ws.soap.Addressing;

/**
 * 监听VIP过期
 */
@Slf4j
@Component
public class VipBindingMemberEndService {

    @Autowired
    private YytMemberService yytMemberService;

    @RabbitListener(queues = "yuanjuDelayedVipQueue")
    public void VipEndTimeLose(String memberId){
        YytMember yytMember = yytMemberService.getById(memberId);
        if(yytMember != null && yytMember.getIsVip().equals("1")){
            UpdateWrapper<YytMember> wrapper = new UpdateWrapper<>();
            wrapper.eq("id", yytMember.getId()).set("is_vip", "0").set("vip_end_time", null);
            boolean update = yytMemberService.update(wrapper);
            log.info("该会员身份已失效", yytMember.getNickname());
        }
    }

}
